﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuxiWTO.Mapping;
using WutiWTO.Common;

namespace WuxiWTO.Web.backend
{
    public partial class Login : System.Web.UI.Page
    {
        WTODataContext ctx = new WTODataContext();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnLogin_Click(object sender, ImageClickEventArgs e)
        {
            if (this.txtName.Text.Trim() == "")
            {
                ClientScript.RegisterStartupScript(this.GetType(), "nameerr", "alert('请填写用户名');", true);
                return;
            }
            if (this.txtPass.Text.Trim() == "")
            {
                ClientScript.RegisterStartupScript(this.GetType(), "passerr", "alert('请填写密码');", true);
                return;
            }
            var admin = ctx.admins.SingleOrDefault(p => p.admin_login_name == this.txtName.Text.Trim() && p.admin_password == this.txtPass.Text.Trim());
            if (admin == null)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "passerr", "alert('用户名或者密码错误，请重新填写');", true);
                return;
            }
            else
            {
                Session["login_name"] = admin.admin_login_name;
                Session["admin_type"] = admin.admin_type;
                Session["admin_name"] = admin.admin_name;
                Response.Redirect("main.aspx");
            }
        }
    }
}